// https://leetcode-cn.com/problems/coin-change/submissions/

class Solution {
public:
    int coinChange(vector<int>& coins, int amount) {
        vector<int> rec(amount + 1, INT_MAX);
        rec[0] = 0; //注意！！！
        for (int i = 0; i < coins.size(); ++i) {
            for (int j = coins[i]; j <= amount; ++j) {
                if (rec[j - coins[i]] != INT_MAX) //注意！！！
                    rec[j] = min(rec[j], rec[j - coins[i]] + 1);
            }
        }
        if (rec.back() == INT_MAX) return -1; //注意！！！
        return rec.back();
    }
};